package com.szholly.data.jdbc;

import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import com.szholly.data.general.GlobalParameter;

public class ParameterHelper {

	public static SqlParameterSource BindParameter(GlobalParameter[] para){
		if(para==null){
			return null;
		}
		
		Map<String,Object> paramters = new HashMap<String,Object>();	
		for (GlobalParameter dbp : para) {
			if(dbp==null){
				continue;
			}
			if (dbp.getParaValue() instanceof java.util.Date) {
				java.util.Date aa = (java.util.Date) dbp.getParaValue();
				Object obj = new java.sql.Timestamp(aa.getTime());
				paramters.put(dbp.getParaName().replace("@", "").replace(":", ""), obj);
			}else{
				paramters.put(dbp.getParaName().replace("@", "").replace(":", ""), dbp.getParaValue());
			}
		}
		
		SqlParameterSource source= new MapSqlParameterSource(paramters);
		return source;
	}
}
